package com.pig4cloud.pig.demo.Controller;


import com.pig4cloud.pig.common.security.annotation.Inner;
import com.pig4cloud.pig.demo.Service.CarouselService;
import com.pig4cloud.pig.demo.Service.impl.ArticleBriefsService;
import com.pig4cloud.pig.demo.feign.Entity.ArticleBriefs;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("demo3")
@Inner
//@CrossOrigin
public class ArticleBriefsController {
    @Autowired
    private ArticleBriefsService articleBriefsService;
    @Autowired
    private CarouselService carouselService;

    @GetMapping("findArticleBriefs")
    public List<ArticleBriefs> findArticleBriefs() throws Exception {
        System.out.println("执行了findArticleBriefs");
        ArticleBriefs articleBriefs = articleBriefsService.findArticleBriefs();
        List<ArticleBriefs> list=new ArrayList<>();
        list.add(articleBriefs);
        return list;
    }

    @GetMapping("findAllArticleBriefs")
    public  Map<String,List<ArticleBriefs>> findAllArticleBriefs() throws Exception{
        System.out.println("执行findAllArticleBriefs");
        Map<String,List<ArticleBriefs>> map= new HashMap();
        List<ArticleBriefs> list = articleBriefsService.findAllArticleBriefs();
        map.put("热门文章",list);
        return map;
    }


    @PostMapping("findAllByClass/{isFree}")
    public Map<String,List<ArticleBriefs>> findAllByClass(@RequestBody List<String> categories, @PathVariable(name="isFree") int isFree) throws IOException, ParseException {
        Map<String, List<ArticleBriefs>> map = articleBriefsService.findAllByClass(categories,isFree);
        System.out.println("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxisFree:"+isFree);
        return map;
    }

    //获取轮播图列表
    @GetMapping("findCarouselList")
    public List<String> findCarouselList(){
        List<String> list = carouselService.getCarouselList();
        return list;
    }

    //保存轮播图
    @GetMapping("saveCarousel/{img}")
    public void saveCarousel(@PathVariable(name="img") String img){
        carouselService.saveCarousel(img);
    }
}
